/**
 * copyright(c) 2013 www.jiongshibaoliao.com, All Rights Reserved.
 * project: jiongshibaoliao 
 * author: 曾帅
 * date: 2013-12-27 下午01:53:01
 * version: v1.0
 */

package com.jiongshibaoliao.web;

import javax.servlet.http.HttpServletRequest;

import com.jiongshibaoliao.model.bean.UserBean;

/**
 * @project jiongshibaoliao
 * @author 曾帅
 * @version 1.0
 * @date 2013-12-27 下午01:53:01
 */

public abstract class BaseController {

	protected final static String SUCCESS = "/public/success";

	protected final static String ERROR = "/public/error";

	protected UserBean sessionUser(HttpServletRequest request) {
		return (UserBean) request.getSession().getAttribute(UserBean.USER_SESSION_KEY);
	}
	
	public String getClientIp(HttpServletRequest request) {
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		if (ip != null && ip.indexOf(",") > 0) {
			ip = ip.substring(0, ip.indexOf(","));
		}
		
		return ip;
	}
	
}
